Skip to content

feat: feishu_doc Markdown 富文本写入 - #122

Merged
lishuceo merged 4 commits into
mainfrom
feat/claude-session-7b4466
Mar 9, 2026
Merged

feat: feishu_doc Markdown 富文本写入#122
lishuceo merged 4 commits into
mainfrom
feat/claude-session-7b4466

Conversation

@lishuceo

@lishuceo lishuceo commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • feishu_doc 工具的 write/append 操作升级为支持 Markdown 自动转换为飞书富文本 Block
  • 之前写入的 # 标题 - 列表 等 markdown 语法在飞书文档中显示为字面字符,现在会正确渲染为标题、列表、代码块等格式
  • 新增 markdown-to-blocks.ts 转换器,支持:heading 1-6、bullet/ordered list、fenced code block(含语言识别)、todo checkbox、divider、inline formatting(bold/italic/code/link/strikethrough)
  • 支持批量写入(每批 50 block),适配飞书 API 限制
  • 39 个单元测试覆盖各种 Markdown 语法

Test plan

  • npx vitest run — 全部测试通过(含 39 个新增 markdown-to-blocks 测试 + 10 个更新的 doc 测试)
  • npx tsc --noEmit — 类型检查通过
  • npx eslint src/ — 0 errors
  • 线上验证:让 agent 写一段包含标题、列表、代码块的 markdown 到飞书文档,确认渲染正确

🤖 Generated with Claude Code

write/append 操作不再写入纯文本 block,改为将 Markdown 内容解析为
对应的飞书 block 结构(heading/bullet/ordered/code/todo/divider 等),
文档渲染效果与原生编辑一致。

- 新增 markdown-to-blocks.ts 转换器,支持标题/列表/代码块/行内格式等
- 支持批量写入(每批 50 block),适配飞书 API 限制
- 39 个单元测试覆盖各种 Markdown 语法

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 2m 2s —— View job


PR Review: feat: feishu_doc Markdown 富文本写入

  • Check for previous review comments
  • Read changed files and understand context
  • Review markdown-to-blocks.ts (new, 355 lines)
  • Review doc.ts changes
  • Review test files
  • Post review summary

✅ Approved — clean implementation with minor suggestions

Overall assessment: This is a well-structured PR. The markdown-to-blocks converter is thorough, handles edge cases sensibly (tables → code block fallback, blockquotes → text fallback), and the test coverage with 39 new tests is solid. The integration into doc.ts is clean and minimal — only the write/append paths changed, replacing raw text insertion with the new block conversion + batching.

2 minor suggestions posted as inline comments:

  • 🟡 Unclosed code fence (confidence: 82) — An opening ``` with no closing fence silently consumes all remaining lines. The i++ on line 197 increments past lines.length, which is harmless but means truncated LLM output could lose trailing content. Suggested a guard: only skip closing fence if found.

  • 🟡 encodeURI double-encoding (confidence: 78) — encodeURI(rawUrl) on line 117 will corrupt pre-encoded URLs (e.g. %20%2520). Since markdown links are typically well-formed, passing the URL through directly or using new URL().href would be safer.

Things done well:

  • Correct batch splitting (50 blocks per request) to respect Feishu API limits
  • Todo checkbox parsing ordered before bullet list parsing (avoids - [ ] being captured as a bullet)
  • Long content splitting in splitLongContent with line-boundary awareness
  • Comprehensive language map for code blocks
  • Tests cover inline formatting, all block types, mixed content, and edge cases (empty input, whitespace-only)

Comment thread src/feishu/tools/markdown-to-blocks.ts Outdated
Comment thread src/feishu/tools/markdown-to-blocks.ts
…locks

支持精确编辑他人文档,不再只能全量覆写:
- update_block: 更新指定 block 的文本内容(支持 inline markdown)
- insert_blocks: 在指定位置插入新 block(支持 markdown → 富文本)
- delete_blocks: 删除指定 block(自动解析 parent + index)

推荐工作流: list_blocks → 找到 block_id → update/insert/delete

9 个新增测试覆盖三个操作的正常和异常路径

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 47s —— View job


PR Review: feat: feishu_doc Markdown 富文本写入 (re-review after sync)

  • Check previous review comments and resolve fixed issues
  • Read current changed files
  • Review for new issues
  • Post summary

⚠️ Issues Found

Previous issues (2 still open):

  • 🟡 Unclosed code fence (markdown-to-blocks.ts:197) — still present, not addressed in new commit
  • 🟡 encodeURI double-encoding (markdown-to-blocks.ts:117) — still present, not addressed in new commit

New issue (1):

  • 🔴 insert_blocks batch ordering bug (doc.ts:185-195, confidence: 90) — When content exceeds 50 blocks, each batch is inserted at the same index, resulting in batches appearing in reverse order. Fix: increment index by batch.length after each insertion.

New code in commit 4bfb88a (block-level edit operations) is otherwise clean:

  • update_block correctly uses parseInlineMarkdown for single-block text updates
  • delete_blocks properly resolves parent → child index before calling batchDelete
  • Input validation with validateToken for block_id is good
  • Test coverage for the 3 new actions is thorough (7 new test cases)

Comment thread src/feishu/tools/doc.ts
- insert_blocks 多批次写入时 index 逐批递增,修复乱序 bug
- 所有 API 调用 (batchUpdate/create/batchDelete) 增加 resp.code 校验
- update_block 描述明确仅支持行内 Markdown
- index 参数增加 int().min(0) 验证
- 新增 5 个测试覆盖 API 错误传播和多批次 index 递增

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 25s —— View job


PR Review: feat: feishu_doc Markdown 富文本写入 (re-review after sync)

  • Check previous review comments and resolve fixed issues
  • Read current changed files
  • Review for new/remaining issues
  • Post summary

⚠️ Issues Found — 1 fixed, 2 still open

Previous issues status:

  • insert_blocks batch ordering bug — Fixed in 8fda34a. Now correctly increments currentIndex += batch.length after each batch. Thread resolved.
  • 🟡 Unclosed code fence (markdown-to-blocks.ts:197, confidence: 82) — Still present. An opening ``` with no closing fence silently consumes all remaining lines.
  • 🟡 encodeURI double-encoding (markdown-to-blocks.ts:117, confidence: 78) — Still present. encodeURI(rawUrl) corrupts pre-encoded URLs (%20%2520).

Latest commit 8fda34a improvements (all good):

  • Added API response validation (code !== 0 checks) to all previously unchecked API calls in write/append/update_block/delete_blocks
  • Added z.number().int().min(0) validation on the index parameter
  • Improved update_block tool description to clarify inline-only Markdown support

Overall: The critical bug (batch ordering) is fixed. The two remaining warnings are low-severity edge cases — the unclosed fence issue only affects truncated LLM output, and the encodeURI issue only affects pre-encoded URLs. Both are safe to address in a follow-up.

…e-encoding

- 未闭合代码块 fence 不再越界跳过额外行
- 移除 encodeURI() 避免已编码 URL 被双重编码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 55s —— View job


PR Review: feat: feishu_doc Markdown 富文本写入 (re-review after fixes)

  • Check previous review comments and verify fixes
  • Read current changed files
  • Review for any remaining issues
  • Resolve fixed comment threads
  • Post summary

✅ Approved — all previous issues fixed

Previous issues (3 resolved):

  • Unclosed code fence — Fixed in 52fd448. Added if (i < lines.length) i++ guard so unclosed fences no longer skip past array bounds.
  • encodeURI double-encoding — Fixed in 52fd448. Removed encodeURI(), raw URL is passed directly to the Feishu API.
  • insert_blocks batch ordering — Fixed in 8fda34a. currentIndex += batch.length correctly maintains insertion order.

No new issues found. The latest commit cleanly addresses both remaining warnings. Code looks good to merge.

@lishuceo
lishuceo merged commit ca832ac into main Mar 9, 2026
6 checks passed
@lishuceo
lishuceo deleted the feat/claude-session-7b4466 branch March 9, 2026 14:55
lishuceo added a commit that referenced this pull request Apr 8, 2026
* feat: feishu_doc write/append 支持 Markdown → 飞书富文本 Block 自动转换

write/append 操作不再写入纯文本 block,改为将 Markdown 内容解析为
对应的飞书 block 结构(heading/bullet/ordered/code/todo/divider 等),
文档渲染效果与原生编辑一致。

- 新增 markdown-to-blocks.ts 转换器,支持标题/列表/代码块/行内格式等
- 支持批量写入(每批 50 block),适配飞书 API 限制
- 39 个单元测试覆盖各种 Markdown 语法

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: feishu_doc 新增 block 级编辑操作 — update_block/insert_blocks/delete_blocks

支持精确编辑他人文档,不再只能全量覆写:
- update_block: 更新指定 block 的文本内容(支持 inline markdown)
- insert_blocks: 在指定位置插入新 block(支持 markdown → 富文本)
- delete_blocks: 删除指定 block(自动解析 parent + index)

推荐工作流: list_blocks → 找到 block_id → update/insert/delete

9 个新增测试覆盖三个操作的正常和异常路径

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: feishu_doc API 响应校验 + insert_blocks 多批次 index 递增

- insert_blocks 多批次写入时 index 逐批递增,修复乱序 bug
- 所有 API 调用 (batchUpdate/create/batchDelete) 增加 resp.code 校验
- update_block 描述明确仅支持行内 Markdown
- index 参数增加 int().min(0) 验证
- 新增 5 个测试覆盖 API 错误传播和多批次 index 递增

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address PR review feedback — unclosed fence guard + remove double-encoding

- 未闭合代码块 fence 不再越界跳过额外行
- 移除 encodeURI() 避免已编码 URL 被双重编码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant